package com.baizhi.chario;

import java.io.*;

/**
 * 通过字符流Copy文件
 *  字节流能拷贝什么    什么也能拷贝
 *  字符流能拷贝什么？  只能拷贝纯文本
 *
 *  只能copy 纯文本内容  中文乱码解决
 */
public class Copy5 {
    public static void main(String[] args) throws IOException {

        long start = System.currentTimeMillis();

        FileInputStream fis = new FileInputStream("F:\\天龙八部.txt"); //源文本是GBK格式
        InputStreamReader fsr = new InputStreamReader(fis,"GBK");  //按照GBK转换成字节
        BufferedReader br = new BufferedReader(fsr);

        //目标文件是ＵＴＦ－８
        FileOutputStream fos = new FileOutputStream("./javase_io/天龙八部_copy.txt");
        OutputStreamWriter osw = new OutputStreamWriter(fos,"UTF-8"); //按照UTF-　8解析
        BufferedWriter bw = new BufferedWriter(osw);


        char[] chars = new char[1000];


        int len;
        while((len=br.read(chars))!=-1){
            bw.write(chars,0,len);
        }

        bw.close();
        br.close();

        long end = System.currentTimeMillis();

        System.out.println("拷贝完毕，耗时："+ (end-start)+"ms");


    }
}
